#pragma once

#include <memory>
#include <vector>

#include <btBulletDynamicsCommon.h>
#include "physics_IRigid.h"
#include <physics_RigidParam.h>
#include "physics_IJoint.h"

class BulletRigid;
class IPhysicsRigid;
struct JointParam;

class BulletModel {
public:
	BulletModel(std::unique_ptr<btDiscreteDynamicsWorld> &rupWorld);
	~BulletModel();

	int AddRigid(RigidBodyParam &param);
	void DeleteRigid(int id);
	int AddJoint(JointParam &param, int rigidId_1, int rigidId_2);
	void DeleteJoint(int id);

	//void AttachRigidToWorld(int id);
	//void DetachRigidFromWorld(int id);
	//void AttachJointToWorld(int id);
	//void DetachJointFromWorld(int id);
	void AttachToWorld();
	void DetachToWorld();

	btVector3 GetWorldCenterPos(int id);
	void GetWorldCenterMatrix(int id, float *pMatrix) ;
	void SetWorldCenterMatrix(int id, float *pMatrix) ;

private:
	std::vector<RigidBodyParam> m_params;
	std::vector<std::unique_ptr<btCollisionShape>> m_upShapes;
	std::vector<std::unique_ptr<btDefaultMotionState>> m_upMotionStates;
	std::vector<std::unique_ptr<btRigidBody>> m_upRigidBodys;

	std::vector<std::unique_ptr<btGeneric6DofSpringConstraint>> m_upConstraints;

	std::unique_ptr<btDiscreteDynamicsWorld> &m_rupWorld;
	bool m_attached = false;
};